package Others.DesignPattern.PrototypePattern.Pattern.Object2;

import lombok.Data;

@Data
public class DeepCloneResume implements Cloneable{

    //这里lombok使用的是setWorkExperience(new ShallowWorkExperience)--这里使用new的话，不属于是克隆的效果

    private String name;
    private String sex;
    private String age;
    private DeepWorkExperience workExperience;

    public DeepCloneResume() {
    }

    private DeepCloneResume(DeepWorkExperience workExperience) throws CloneNotSupportedException {
        this.workExperience = (DeepWorkExperience)workExperience.clone();
    }

    public DeepCloneResume(String name, String sex, String age, DeepWorkExperience workExperience) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.workExperience = workExperience;
    }

    public void setDeepWorkExperience(String timeArea, String company){
        this.getWorkExperience().setTimeArea(timeArea);
        this.getWorkExperience().setCompany(company);
    }

    public void show(){
        System.out.println("姓名：" + name + "  性别：" + sex + "  年龄：" + age + "  工作年限：" + workExperience.getTimeArea() + "  工作经历：" + workExperience.getCompany());
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        DeepCloneResume deepCloneResume = new DeepCloneResume(this.workExperience);
        deepCloneResume.setName(this.name);
        deepCloneResume.setSex(this.sex);
        deepCloneResume.setAge(this.age);
        return deepCloneResume;
    }

}
